# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-brass
pkgver=1.2.1
pkgrel=2
pkgdesc='Bare-Metal Ruby Assertions System Standard'
arch=(any)
url='https://github.com/rubyworks/brass'
license=(BSD)
depends=(ruby)
checkdepends=(ruby-lemon ruby-rubytest-cli ruby-simplecov)
options=(!emptydirs)
source=(https://github.com/rubyworks/brass/archive/$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('8f3f97e35014753155ccbc91c64543012628cdfebb0593550e46abb78973ee8c')

prepare() {
  cd brass-$pkgver
  sed -e '1i require "simplecov"' \
      -e "/cov.coverage_dir/d" \
      -i .test
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd brass-$pkgver
  gem build .gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    brass-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd brass-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rubytest test
}

package() {
  cd brass-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 COPYING.rdoc -t "$pkgdir"/usr/share/licenses/$pkgname/
}
